package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.MemberManagerService;
import com.mtnz.njk.entity.NjkUserServiceEntity;
import com.mtnz.njk.result.ResponseMessage;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 成员管理控制层
 * @Author: FBL
 * @CreateDate: 2019\8\26 0026 11:51
 * @Version: 1.0
 */
@RestController
@RequestMapping("/member")
@CrossOrigin
public class MemberManagerController {

    @Autowired
    MemberManagerService memberManagerService;

    /**
     * 成员管理列表
     *
     * @param key
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listMember")
    public ResponseResult listMember(String key, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return memberManagerService.listMember(key, pageNum, pageSize);
    }

    /**
     * 成员管理列表编辑
     *
     * @param serviceEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateMember")
    public ResponseResult updateMember(@RequestBody NjkUserServiceEntity serviceEntity) throws Exception {
        if (serviceEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return memberManagerService.updateMember(serviceEntity);
    }

    /**
     * 成员管理列表新增
     *
     * @param serviceEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertMember")
    public ResponseResult insertMember(@RequestBody NjkUserServiceEntity serviceEntity) throws Exception {
        if (serviceEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return memberManagerService.insertMember(serviceEntity);
    }

}
